﻿@typeparam TItem
@inject IDataCacheService _dataCacheService
@inject NavigationManager NavigationManager


@if (string.IsNullOrWhiteSpace(Title) == false)
{
    <div class="card-title">
        <h2>@Title</h2>
        @if (string.IsNullOrWhiteSpace(MoreLink) == false|| ForceShowMore)
        {
            <div>
                @if (_dataCacheService.IsApp)
                {
                    <MButton XSmall Text Block Color="primary" OnClick="@OnClick" Href="@MoreLink">
                        <MIcon Left>@MoreIcon.ToIconString()</MIcon>
                        @MoreText
                    </MButton>
                }
                else
                {
                    <MButton Text Block Color="primary" OnClick="@OnClick" Href="@MoreLink">
                        <MIcon Left>@MoreIcon.ToIconString()</MIcon>
                        @MoreText
                    </MButton>
                }
            </div>       
        }
    </div>
}

@if (_dataCacheService.IsApp)
{
    <div class="slide-group">
        @foreach (var item in Items)
        {
            <div class="slide-item">
                @ChildContent(item)
            </div>

        }
    </div>
}
else
{
    <MSlideGroup ShowArrows="true" >
        @foreach (var item in Items)
        {
            <MSlideItem>
                @ChildContent(item)
            </MSlideItem>

        }

        @if (string.IsNullOrWhiteSpace(MoreLink) == false|| ForceShowMore)
        {
            <MSlideItem>
                <MDCard Class="item more-link pointer" Href="@MoreLink" OnClick="OnClick" ShowHoverStyle="true">
                    <MIcon Large>@((MoreIcon == IconType.SeeDetails ? IconType.SeeMore : MoreIcon).ToIconString())</MIcon>
                 <div class="text">@MoreText</div>

                </MDCard>
            </MSlideItem>
        }
    </MSlideGroup>

}

@code {
    [Parameter]
    public RenderFragment<TItem> ChildContent { get; set; }
    [Parameter]
    public IEnumerable<TItem> Items { get; set; }
    [Parameter]
    public EventCallback OnClickMore { get; set; }

    [Parameter]
    public string MoreLink { get; set; }
    [Parameter]
    public IconType MoreIcon { get; set; } = IconType.SeeDetails;
    [Parameter]
    public bool ForceShowMore { get; set; }
    [Parameter]
    public string MoreText { get; set; } = "查看更多";
    [Parameter]
    public string Title { get; set; }


    public async Task OnClick()
    {
        if (string.IsNullOrWhiteSpace(MoreLink))
        {
            await OnClickMore.InvokeAsync();
        }
    }
}
